package com.esyoga.yoyoga.util;

import java.util.ArrayList;
import java.util.List;

/**
 * 图片拼接工具类，用于存取添加时的路径字符串拼接
 */
public class PictureInvertUtil {
    private PictureInvertUtil(){}

    /**
     * 用于获取拼接好的图片路径
     * @param pathsList 路径List
     * @return          拼接好的字符串
     */
    public static String getPathsString(List<String> pathsList){
        if (pathsList.size()==0||pathsList==null)return "";
        String paths = pathsList.get(0);
        for (int i = 1; i < pathsList.size(); i++){
            paths += ";"+pathsList.get(i);
        }
        return paths;
    }

    /**
     * 用于获取图片路径List
     * @param paths 拼接好的字符串
     * @return      路径List
     */
    public static List<String> getPathsList(String paths){
        if (paths.length()==0||paths==null)return new ArrayList<>();
        String[] strs = paths.split(";");
        List<String> pathsList = new ArrayList<>();
        for (int i = 0; i < strs.length; i++) {
            pathsList.add(strs[i]);
        }
        return pathsList;
    }

    /**
     * 用于添加图片路径（通过List）
     * @param paths         已有的图片路径字符串
     * @param addPathsList  添加图片路径的List
     * @return              添加后的图片路径拼接字符串
     */
    public static String addPathsByList(String paths,List<String> addPathsList){
        String currentPaths;
        if (paths.length()==0||paths==null){
            currentPaths = getPathsString(addPathsList);
        }else{
            currentPaths = paths +";"+ getPathsString(addPathsList);
        }
        return currentPaths;
    }

    /**
     * 用于添加图片路径（通过String）
     * @param paths     已有的图片路径字符串
     * @param addPaths  添加图片路径的String，可以是单个的，可以是拼接好的
     * @return          添加后的图片路径拼接字符串
     */
    public static String addPathsByString(String paths,String addPaths){
        if (addPaths.length()==0||addPaths==null)return paths;
        List<String> addPathsList = getPathsList(addPaths);
        paths = addPathsByList(paths,addPathsList);
        return paths;
    }

    /**
     * 用于删除图片路径（通过List）
     * @param paths             已有的图片路径字符串
     * @param deletePathsList   删除图片路径的List
     * @return                  删除后的图片路径拼接字符串
     */
    public static String deletePathsByList(String paths,List<String> deletePathsList){
        if (deletePathsList.size()==0||deletePathsList==null) return paths;
        String deletedPath = getPathsString(deletePathsList);
        deletePathsByLString(paths,deletedPath);
        return paths;
    }

    /**
     * 用于删除图片路径（通过String）
     * @param paths         已有的图片路径字符串
     * @param deletePath    删除图片路径的String，可以是单个的，可以是拼接好的
     * @return              删除后的图片路径拼接字符串
     */
    public static String deletePathsByLString(String paths,String deletePath){
        if (paths.length()==0||paths==null) return "";
        if (deletePath.length()==0||paths==null) return paths;
        List<String> pathsList = getPathsList(paths);
        List<String> deletePathsList = getPathsList(deletePath);
        pathsList.removeAll(deletePathsList);
        paths = getPathsString(pathsList);
        return paths;
    }



}
